import {
  reqGetJobCategoryList,
  reqBatchAddJobCategory,
  reqEditJobCategory,
  reqBatchDelJobCategory,
  reqGetCategories,
  reqCheckJobCategoryCodeIsRepeat,
  reqGetJobNameListByPid,
} from '@/views/Custom/JobCategoryMng/api/JobCategoryMngApi';
const actions = {
  // 查询全部工作类别信息
  async getJobCategoryList({ commit }, params) {
    let result = await reqGetJobCategoryList(params);
    commit('GETJOBCATEGORYLIST', result.data.jobCategoryIPage);
  },
  // 工作类别信息新增
  async batchAddJobCategory({ commit }, params) {
    let result = await reqBatchAddJobCategory(params);
    return result;
  },
  // 工作类别编辑
  async editJobCategory({ commit }, params) {
    let result = await reqEditJobCategory(params);
    return result;
  },
  // 工作类别删除
  async delJobCategory({ commit }, params) {
    let result = await reqBatchDelJobCategory(params);
    return result;
  },
  // 获取大类
  async getCategories({ commit }) {
    let result = await reqGetCategories();
    commit('GETCATEGORIES', result.data.categories);
  },
  // 检测职位名称是否重复
  async checkIsRepeatForJobCategoryName({ commit }, params) {
    let result = await reqCheckJobCategoryCodeIsRepeat(params);
    return result;
  },

  // 根据pid 查询编号与名称
  async getIdAndNameList({ commit }, params) {
    let result = await reqGetJobNameListByPid(params);
    commit('GETIDANDNAMELIST', result.data.jobNameAndIdList);
  },
};
const mutations = {
  GETJOBCATEGORYLIST(state, result) {
    state.jobCategoryIPage = result;
  },
  // 获取工作大类别
  GETCATEGORIES(state, result) {
    state.categories = result;
  },
  // 根据pid 查询编号与名称
  GETIDANDNAMELIST(state, result) {
    state.jobNameAndIdList = result;
  },
};
const state = {
  jobCategoryIPage: {},
  jobCategoryList: [],
  categories: [],
  jobNameAndIdList: [],
};
const getters = {
  // 工作类别分页查询后的包装数据
  jobCategoryIPage(state) {
    return state.jobCategoryIPage || [];
  },
  // 工作类别列表
  jobCategoryList(state) {
    return state.jobCategoryIPage ? state.jobCategoryIPage.records || [] : [];
  },
  jobCategoryIdAndNameAndCodeList(state) {
    return state.jobCategoryIdAndNameAndCodeList || [];
  },
  categories(state) {
    return state.categories || [];
  },
  // 工作名称与编号列表
  jobNameAndIdList(state) {
    return state.jobNameAndIdList || [];
  },
};
export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
};
